<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 2018/6/20
 * Time: 14:17
 */

namespace app\admin\controller;


use app\admin\Controller;
use app\common\model\Ccp as CcpModel;

class Ccp extends Controller
{
    use \app\admin\traits\controller\Controller;

    public function add()
    {
        if ($this->request->isAjax()) {
            $data = $this->request->param()['data'];
            $data['content'] = urldecode($data['content']);
            $time = time();
            $data['create_time'] = $time;
            $data['update_time'] = $time;
            CcpModel::create($data);
            return ajax_return_adv('添加成功');
        } else {
            return $this->view->fetch('add');
        }
    }

    public function edit()
    {
        if ($this->request->isAjax()) {
            $data = $this->request->param()['data'];
            $data['content'] = urldecode($data['content']);
            $data['update_time'] = time();
            CcpModel::update($data);
            return [
                'code' => 0,
                'msg' => 'success'
            ];
        } else {
            $id = $this->request->param('id');
            $ccp = CcpModel::get($id);
            $this->view->assign('ccp', $ccp);
            return $this->view->fetch('edit');
        }
    }
}